package com.xxd.spring.boot.demo.hexinglei.controller;



import com.xxd.spring.boot.demo.hexinglei.Result;
import com.xxd.spring.boot.demo.hexinglei.constant.ConstantData;
import com.xxd.spring.boot.demo.hexinglei.entity.User;
import com.xxd.spring.boot.demo.hexinglei.exception.MyException;
import com.xxd.spring.boot.demo.hexinglei.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/regist")
    public Result regist(@RequestBody User user) throws MyException {
        userService.regsit(user);
        return new Result().success();
    }

    @RequestMapping("/login")
    public Result login(@RequestBody User user) throws MyException {
        User dbUser = userService.login(user.getUsername(),user.getPassward());
        String uuid = UUID.randomUUID().toString();
        ConstantData.userMap.put(uuid,dbUser);
        return new Result().success().setData(uuid);
    }

}
